<template>
  <el-dialog title="编辑分类" :visible.sync="visible" width="30%" @close="resetForm">
    <el-form :model="form" label-width="100px" ref="form">
      <el-form-item label="分类名称" prop="name">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="分类类型" prop="type">
        <el-select v-model="form.type" placeholder="请选择分类类型" disabled>
          <el-option label="菜品分类" :value="1"></el-option>
          <el-option label="套餐分类" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input v-model="form.sort" type="number"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="submitForm">保存</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      form: {
        id: null,
        name: "",
        type: null, // 1: 菜品分类, 2: 套餐分类
        sort: 0,
      },
    };
  },
  methods: {
    open(row) {
      this.form = { ...row }; // 填充表单数据
      this.visible = true;
    },
    resetForm() {
      this.$refs.form.resetFields();
    },
    submitForm() {
      this.$emit("submit", this.form);
      this.visible = false;
    },
  },
};
</script>